<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Cộng điểm</title>
<script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
	var tongdiem=0;
	var soluong=0;
	function tachdiem(diem, heso) {
		var d=diem.split(" ");
		if (diem.length>0)
		for (var i=0; i<d.length;i++) {
			if (d[i].length>0) {
				var x = parseInt(d[i]);
				tongdiem+= x*heso;
				soluong+=heso;
			}
		}
	}
	$(".diem").change(tinhdiem);
	$("#diemtbm").click(function(){
		tinhdiem();
	});
	function tinhdiem() {
		tongdiem=0;
		soluong=0;
		//alert($("#diem_hs1").val());
		for (var j=1; j<=3; j++) {
			
			tachdiem($("#diem_hs"+j).val(),j);
		}
		if (soluong>0) {
			$("#tbm").html(Math.round(tongdiem/soluong));
		} else {
			$("#tbm").html("");
		}
	}
});
</script>
</head>

<body>
<div align="center">
<h3 id="diemtbm">CỘNG ĐIỂM BỘ MÔN - THPT</h3>
<table border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td>Hệ số 1: </td>
		<td><input type="text" class="diem" id="diem_hs1"></td>
	</tr>
	<tr>
		<td>Hệ số 2: </td>
		<td><input type="text" class="diem" id="diem_hs2"></td>
	</tr>
	<tr>
		<td>Hệ số 3: </td>
		<td><input type="text" class="diem" id="diem_hs3"></td>
	</tr>
	<tr>
		<td>TBM: </td>
		<td><span id="tbm">&nbsp;</span></td>
	</tr>
</table>

</div>
</body>
</html>
